package com.bt.lms.ui.page.classes;

import com.bt.lms.ui.action.divide.plan.BackBtnAction;
import com.bt.lms.ui.action.divide.plan.ManualShiftBtnAction;
import com.bt.lms.ui.action.divide.plan.PreviewResultsBtnAction;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Cursor;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;

import java.util.ArrayList;
import java.util.List;

/**
 * 随机平均分班页面
 */
public class PageRandomShift extends VBox {

    /**
     * 大盒子
     */
    VBox vBox = new VBox();

    /**
     * 宽
     */
    private Integer preWidth = 1280;

    /**
     * 高
     */
    private Integer preHeight = 600;


    public PageRandomShift() {
        vBox.setPrefSize(preWidth, preHeight);
        vBox.setSpacing(40);
        vBox.setPadding(new Insets(20));
        Label topLab = new Label("共有350名学员");
        Font font = Font.font("仿宋", FontWeight.BLACK, FontPosture.REGULAR, 25);
        topLab.setFont(font);
        //分班方式盒子
        HBox hBox = new HBox();
        hBox.setSpacing(10);
        Label chooseLab = new Label("请选择分班方式：");
        Button randomShiftBtn = new Button("随机平均分班");
        randomShiftBtn.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        Color rgb = Color.rgb(49, 193, 231);
        BackgroundFill backgroundFill = new BackgroundFill(rgb, null, null);
        Background background = new Background(backgroundFill);
        randomShiftBtn.setBackground(background);

        Button manualShiftBtn = new Button("手动分班");
        manualShiftBtn.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        manualShiftBtn.setBackground(background);
        hBox.getChildren().addAll(chooseLab, randomShiftBtn, manualShiftBtn);
        //事件
        ManualShiftBtnAction manualShiftBtnAction = new ManualShiftBtnAction();
        manualShiftBtn.setOnAction(manualShiftBtnAction);
        //填写分班数
        //输入生成的数据盒子
        VBox vBox1 = new VBox();
        vBox1.setSpacing(40);

        HBox hBox1 = new HBox();
        hBox1.setSpacing(10);
        Label writeLab = new Label("填写分班数");
        TextField writeTF = new TextField();
        writeTF.setId("writeTF"); //设置ID
        Button affirmBtn = new Button("确认");
        affirmBtn.setBackground(background);

        affirmBtn.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        hBox1.getChildren().addAll(writeLab, writeTF, affirmBtn);

        //标签
        Label tipLab = new Label("已分成4个班，成功分配学员350名，请设定班级名称");

        HBox hBox2 = new HBox();
        hBox2.setSpacing(200);
        Label classIDLab = new Label("班ID");
        Label classNameLab = new Label("设定班级名称");
        Label resultLab = new Label("人数分配结果");
        hBox2.getChildren().addAll(classIDLab, classNameLab, resultLab);

        HBox hBox3 = new HBox();
        hBox3.setSpacing(20);
        TextField iDTF = new TextField();
        iDTF.setPromptText("ID001");
        iDTF.setId("iDTF"); //设置ID
        TextField classNameTF = new TextField();
        classNameTF.setPromptText("请输入班级名称");
        classNameTF.setId("classNameTF");//设置ID
        TextField randomStuNoTF = new TextField();
        randomStuNoTF.setPromptText("50");
        randomStuNoTF.setId("randomStuNoTF");
        hBox3.getChildren().addAll(iDTF, classNameTF, randomStuNoTF);

        List<HBox> list = new ArrayList<>();
        list.add(hBox3);
        affirmBtn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                String classNum = writeTF.getText();
                try {
                    int num = Integer.parseInt(classNum);
                    for (int i = 0; i < num - 1; i++) {
                        HBox hBox4 = new RandomCondition().RandomCondition();
                        vBox1.getChildren().add(hBox4);
                        list.add(hBox4);
                    }
                } catch (NumberFormatException e) {

                }
            }
        });
        //按钮盒子
        HBox hBox4 = new HBox();
        hBox4.setSpacing(10);
        Button previewResultsBtn = new Button("预览分班结果");
        previewResultsBtn.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        previewResultsBtn.setBackground(background);
        //预览分班结果事件
        PreviewResultsBtnAction previewResultsBtnAction = new PreviewResultsBtnAction(this,list);
        previewResultsBtn.setOnAction(previewResultsBtnAction);

        Button cancelBtn = new Button("取消");
        cancelBtn.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        //取消事件
        BackBtnAction backBtnAction = new BackBtnAction();
        cancelBtn.setOnAction(backBtnAction);
        hBox4.getChildren().addAll(previewResultsBtn, cancelBtn);

        //滚动条
        ScrollPane scrollPane = new ScrollPane();
        scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); //不让设置横滚动条
        scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);
        scrollPane.setContent(vBox);
        this.getChildren().add(scrollPane);

        vBox.getChildren().addAll(topLab, hBox, hBox1, tipLab, hBox2, hBox3, vBox1, hBox4);
    }
}
